package org.itzixi.mapper;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.ibatis.annotations.Param;
import org.itzixi.enums.YesOrNo;
import org.itzixi.pojo.Friendship;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.itzixi.pojo.dto.FriendshipDTO;
import org.itzixi.pojo.vo.ContactsVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 朋友关系表 Mapper 接口
 * </p>
 *
 * @author 顾文龙
 * @since 2024-06-12
 */
@Repository
public interface FriendshipMapper extends BaseMapper<Friendship> {

    default Friendship selectFriendshipByMyIdAndFriendId(String myId, String friendId){
        QueryWrapper<Friendship> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Friendship::getMyId, myId).eq(Friendship::getFriendId, friendId);
        return this.selectOne(queryWrapper);
    }

    /**
     * 查询好友关系列表
     * @param friendshipDTO 查询条件
     * @return
     */
    List<ContactsVO> queryMyFriends(@Param("friendshipDTO") FriendshipDTO friendshipDTO);

    default void updateFriendRemark(String myId, String friendId, String friendRemark){
        UpdateWrapper<Friendship> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda()
                .set(Friendship::getFriendRemark, friendRemark)
                .set(Friendship::getUpdatedTime, LocalDateTimeUtil.now())
                .eq(Friendship::getMyId, myId)
                .eq(Friendship::getFriendId, friendId);
        this.update(updateWrapper);

    }

    default void updateBlackList (String myId, String friendId, YesOrNo yesOrNo){
        UpdateWrapper<Friendship> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda()
                .set(Friendship::getIsBlack, yesOrNo.type)
                .set(Friendship::getUpdatedTime, LocalDateTimeUtil.now())
                .eq(Friendship::getMyId, myId)
                .eq(Friendship::getFriendId, friendId);
        this.update(updateWrapper);
    }

}
